package com.manager.devicemanager.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.manager.devicemanager.common.DataSourceNameEnum;
import com.manager.devicemanager.entity.Testlog;
import com.manager.devicemanager.service.ITestlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;


// 导入 Result 类，需确保该类存在
import com.manager.devicemanager.common.Result;
import com.manager.devicemanager.vo.PageVO; // 需确保该类存在


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wpf
 * @since 2025-05-29
 */
@RestController
@RequestMapping("/testlog")
public class TestlogController {
    @Autowired
    private ITestlogService testlogService;

    /**
     * 带远程条件筛选的分页查询接口
     * @param testlogPageVO 分页查询条件对象，包含页码、每页数量和查询条件
     * @return 分页查询结果
     */
    @PostMapping("/page")
    public Result<IPage<Testlog>> page(@RequestBody PageVO<Testlog> testlogPageVO) {
        int pageNum = testlogPageVO.getPageNum();
        int pageSize = testlogPageVO.getPageSize();
        Testlog testlog = testlogPageVO.getCondition();
        LambdaQueryWrapper<Testlog> queryWrapper = new LambdaQueryWrapper<>(testlog);
        IPage<Testlog> testlogPage = testlogService.selectPageByICBoardid(("ic".equals(testlogPageVO.getType())?DataSourceNameEnum.ICBOARDCONFIG.getDataSourceName():DataSourceNameEnum.PDBOARDCONFIG.getDataSourceName())+testlogPageVO.getDatasourceindex(),new Page<>(pageNum, pageSize), testlog.getBoardid());
        return Result.success(testlogPage);
    }




}
